﻿using Enterprise_Set.API.Application.Commands.Week1.Warehouse_CRUD;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NLog;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Controllers.Week1
{
    [Route("api/[controller]")]
    [ApiController]
    public class WarehouseController : ControllerBase
    {
        public WarehouseController(IMediator mediator, ILogger<WarehouseController> logger)
        {
            Mediator = mediator;
            this.logger = logger;
        }

        public IMediator Mediator { get; set; }
        public ILogger<WarehouseController> logger { get; set; }
        /// <summary>
        /// 添加仓库
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("AddWarehouseData")]
        public async Task<Result> AddWarehouseData(AddWarehouseCommand cmd)
        {
            try
            {
                logger.LogInformation("添加仓库成功");
                return await Mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("添加仓库失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 删除仓库
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("DelWarehouseData")]
        public async Task<Result> DelWarehouseData(DelWarehouseCommand cmd)
        {
            try
            {
                logger.LogInformation("删除仓库成功");
                return await Mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("删除仓库失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 显示仓库表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("SelWarehouseData")]
        public async Task<Result> SelWarehouseData(SelWarehouseCommand cmd)
        {
            try
            {
                logger.LogInformation("显示仓库成功");
                return await Mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("显示仓库失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 修改仓库表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("UpWarehouseData")]
        public async Task<Result> UpWarehouseData(UpWarehouseCommand cmd)
        {
            try
            {
                logger.LogInformation("修改仓库成功");
                return await Mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("修改仓库失败" + ex.Message);
                throw;
            }
        }
    }
}
